package sk.stuba.fiit.clientApp.service.impl;

import java.security.cert.X509CRL;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import sk.stuba.fiit.clientApp.service.CrlService;
import sk.stuba.fiit.clientApp.ws.client.CRLServiceClient;
import sk.stuba.fiit.pki.ws.schema.beans.CrlRequest;
import sk.stuba.fiit.pki.ws.schema.beans.CrlResponse;
import sun.misc.BASE64Decoder;
import sun.security.x509.X509CRLImpl;

@Service("crlService")
public class CrlServiceImpl implements CrlService {
	
	@Autowired
	private CRLServiceClient crlServiceClient;

	public X509CRL getActualCRL() throws Exception{
		
		CrlRequest request = new CrlRequest();
		CrlResponse  response = crlServiceClient.getActualCrl(request);
		BASE64Decoder decoder = new BASE64Decoder();
		byte[] crlData = decoder.decodeBuffer(response.getCrlresp().get(0));
		X509CRL crl = new  X509CRLImpl(crlData);
		return crl;
	}
}
